﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;

namespace DAO
{
    public class GheDAO : AbstractDAO<GheDTO>
    {

        protected override string GetTableName()
        {
            return "vitridatve";
        }

        public override GheDTO GetByDataRow(System.Data.DataRow data)
        {
            GheDTO gheDTO = new GheDTO();
            gheDTO.ChuyenXeId = int.Parse(data["chuyenxe_id"].ToString());
            gheDTO.MaSoGhe = int.Parse(data["maso"].ToString());
            gheDTO.KhachHangId = int.Parse(data["khachhang_id"].ToString());
            return gheDTO;
        }

        public List<GheDTO> GetByChuyenXeId(int chuyenXeId)
        {
            List<GheDTO> ls = new List<GheDTO>();
            String query = String.Format("SELECT * FROM {0} where chuyenxe_id = {1}", tableName, chuyenXeId);
            DataTable dt = dataProvider.ExecuteQuery(query);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    GheDTO p = GetByDataRow(r);
                    ls.Add(p);
                }
            }
            return ls;
        }

    }
}
